<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "article".
 *
 * @property int $id
 * @property string $title
 * @property string $content
 * @property int $admin_id
 * @property int $cate_id
 * @property string $cover
 * @property int $view_num
 * @property int $view_num_base
 * @property int $status
 * @property int $created_at
 */
class Article extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'article';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['content'], 'string'],
            [['admin_id', 'cate_id', 'article_recom', 'is_recom', 'view_num', 'view_num_base', 'status', 'created_at'], 'integer'],
            [['title', 'cover'], 'string', 'max' => 255],
            [['source'], 'string', 'max' => 64]
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => 'Title',
            'content' => 'Content',
            'admin_id' => 'Admin ID',
            'cate_id' => 'Cate ID',
            'cover' => 'Cover',
            'view_num' => 'View Num',
            'view_num_base' => 'View Num Base',
            'status' => 'Status',
            'created_at' => 'Created At',
        ];
    }

    public function getCate(){
        return $this->hasOne(Category::class, ['id' => 'cate_id']);
    }
}
